package message.visitor.tests;

import junit.framework.Assert;
import message.types.message.RejectedRequest;
import message.types.stalkerstring.GetRoomFromNameAnswer;
import message.types.string.CreatePrivatePersistentRoomRequest;
import message.types.string.CreateRoomRequest;
import message.types.string.GetRoomFromNameRequest;
import message.types.unique.EmptyMessage;
import message.types.unique.RoomInvitation;

import org.junit.Test;

import stalker.Stalker;
import stalker.room.Room;
import stalker.tester.TesterStalker;


public class RoomManagerVisitorTest {
  
  @Test
  public void test01() throws InterruptedException {
    TesterStalker tester = new TesterStalker();
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new CreateRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "lili"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new RoomInvitation(Room.getRoomFromName("lili"), tester, Room.getRoomFromName("lili"), Stalker.ROOM_MANAGER_STALKER)));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new CreateRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "lili"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            Stalker.ROOM_MANAGER_STALKER, 
            tester, 
            new CreateRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "lili")
            )
        ));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new CreateRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "kuman"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new RoomInvitation(Room.getRoomFromName("kuman"), tester, Room.getRoomFromName("kuman"), Stalker.ROOM_MANAGER_STALKER)));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new GetRoomFromNameRequest(tester, Stalker.ROOM_MANAGER_STALKER, "kuman"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new GetRoomFromNameAnswer(Stalker.ROOM_MANAGER_STALKER, tester, Room.getRoomFromName("kuman"), "kuman")));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new GetRoomFromNameRequest(tester, Stalker.ROOM_MANAGER_STALKER, "yunis"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            Stalker.ROOM_MANAGER_STALKER, 
            tester, 
            new GetRoomFromNameRequest(tester, Stalker.ROOM_MANAGER_STALKER, "yunis")
            )
        ));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new CreatePrivatePersistentRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "kuman"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            Stalker.ROOM_MANAGER_STALKER, 
            tester, 
            new CreatePrivatePersistentRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "kuman")
            )
        ));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new CreatePrivatePersistentRoomRequest(tester, Stalker.ROOM_MANAGER_STALKER, "terong"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new RoomInvitation(Room.getRoomFromName("terong"), tester, Room.getRoomFromName("terong"), Stalker.ROOM_MANAGER_STALKER)));
    Thread.sleep(25);
    Stalker.ROOM_MANAGER_STALKER.acceptMessage(new RejectedRequest(Stalker.ROOM_MANAGER_STALKER, tester, new EmptyMessage()));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new RejectedRequest(Stalker.ROOM_MANAGER_STALKER, tester, new EmptyMessage())));
    Thread.sleep(25);
    
  }
  
}
